﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using V = Science.Mathematics.VectorCalculus;

namespace VectorCalculus5Ed.Chapter2.Section5
{
    public class Example03
    {
        public Example03()
		{
		}
		private string result;
		public string Result
		{
			get{return result;}
		}
        public void Compute()
        {
            V.Function.ToLastType<double[], double[]> f
                = new V.Function.ToLastType<double[], double[]>(funcf);
            V.Function.ToLastType<double[], double[]> g
                = new V.Function.ToLastType<double[], double[]>(funcg);

            double[] x0 = { 1.0, 1.0 };

            V.ChainRule obj = new V.ChainRule(f, g, x0);
            obj.Compute();

            result += obj.Result[0, 0].ToString() + "    ";
            result += obj.Result[0, 1].ToString() + "\r\n";
            result += obj.Result[1, 0].ToString() + "    ";
            result += obj.Result[1, 1].ToString() + "\r\n";
            result += obj.Result[2, 0].ToString() + "    ";
            result += obj.Result[2, 1].ToString() + "\r\n";
        }
        private double[] funcf(double[] u)
        {
            double[] r = new double[3];
            r[0] = u[0] + u[1];
            r[1] = u[0];
            r[2] = u[1] * u[1];
            return r;
        }
        private double[] funcg(double[] x)
        {
            double[] r = new double[2];
            r[0] = x[0] * x[0] + 1.0;
            r[1] = x[1] * x[1];        
            return r;
        }
    }
}
/*
1.99999999999969    1.99999999999859
2.00000000000004    0
0    3.99999999999961
*/